/* -*-c++-*- OpenSceneGraph Cookbook
 * Chapter 6 Recipe 10
 * Author: Wang Rui <wangray84 at gmail dot com>
*/

#ifndef H_COOKBOOK_CH6_CGPROGRAM
#define H_COOKBOOK_CH6_CGPROGRAM

#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include <osg/StateAttribute>
#define CGPROGRAM_ID 0x1000

class CgProgram : public osg::StateAttribute
{
public:
    CgProgram() : _initialized(false) {}
    
    CgProgram( const CgProgram& copy, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY )
    :   osg::StateAttribute(copy, copyop),
        _profiles(copy._profiles), _programs(copy._programs),
        _initialized(copy._initialized)
    {}
    
    META_StateAttribute( osg, CgProgram, (osg::StateAttribute::Type)CGPROGRAM_ID );
    
    void addProfile( CGprofile profile );
    void addCompiledProgram( CGprogram prog ) { _programs.push_back(prog); }
    
    virtual int compare( const osg::StateAttribute& sa ) const;
    virtual void apply(osg::State& state) const;
    
protected:
    virtual ~CgProgram() {}
    
    std::vector<CGprofile> _profiles;
    std::vector<CGprogram> _programs;
    mutable bool _initialized;
};

#endif
